class Mypromise{
    
    constructor(executor){
        this.promiseStatus='pending';
        this.value=undefined;
        this.reason=undefined;
        
        this.onFulfilledCallbacks=[];
        this.onRejectedCallbacks=[];
        
        const resolve = (value)=>{
            if(this.promiseStatus==='pending'){
                this.promiseStatus='fulfilled';
                this.value=value;

                this.onFulfilledCallbacks.forEach(callback=>callback());
            }
        }

        const reject = (reason) =>{
            if(this.promiseStatus==='pending'){
                this.promiseStatus='rejected';
                this.reason=reason;

                this.onRejectedCallbacks.forEach(callback=>callback());
            }
        }

        try{
            executor(resolve,reject);
        }catch(error){
            reject(error)
        }

    }

}